#include "admin_svc.h"
#include <butil/logging.h>
#include <cppbase/utility.h>
#include <wf_task/tasks.h>
#include "bthread_task.h"
namespace frpcType
{
    void AdminSvcImpl::UpdateBarSeries(google::protobuf::RpcController *cntl_base, const UpdateBarRequest *request, DefaultArg *response, google::protobuf::Closure *done)
    {

        brpc::ClosureGuard done_guard(done);
        auto task = new UpdateBarTask;
        task->done = done;
        task->request = request;
        brpc::Controller *cntl = static_cast<brpc::Controller *>(cntl_base);
        task->response = response;
        task->cntl = cntl;
        int bufsize = cntl->request_attachment().size();
        if (bufsize == 0)
        {
            cntl->SetFailed(brpc::HTTP_STATUS_BAD_REQUEST, "%s", "zero byte");
            return;
        }
        if (bufsize != request->rowsize() * request->rowcount())
        {
            cntl->SetFailed(brpc::HTTP_STATUS_BAD_REQUEST, "%d,%d!=%d. %s", request->rowsize(), request->rowcount(), bufsize, "byte size error");
            return;
        }

        LOG(INFO) << "call UpdateBarSeries,request attachment size: " << cntl->request_attachment().size();
        bthread_t th;
        CHECK_EQ(0, bthread_start_background(&th, NULL, process_thread, task));
        done_guard.release();
    }
}